package com.suntianci.stock.controller;

import com.suntianci.stock.pojo.domain.*;
import com.suntianci.stock.service.StockService;
import com.suntianci.stock.vo.resp.PageResult;
import com.suntianci.stock.vo.resp.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Param;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * @ClassName StockController
 * @Author 孙天赐
 * @Date 2024/12/26 14:31
 * @Description TODO: 股票相关接口控制器
 */
@RestController
@RequestMapping("/api/quot")
@Api(tags = "股票相关接口处理")
public class StockController {

    @Autowired
    private StockService stockService;

    /**
     * 获取国内大盘最新的数据
     *
     * @return
     */
    @ApiOperation(value = "获取国内大盘最新的数据", notes = "获取国内大盘最新的数据", httpMethod = "GET")
    @GetMapping("/index/all")
    public R<List<InnerMarketDomain>> getInnerMarketInfo() {
        return stockService.getInnerMarketInfo();
    }

    /**
     * 获取国内板块最新的数据
     *
     * @return
     */
    @ApiOperation(value = "获取国内板块最新的数据", notes = "获取国内板块最新的数据", httpMethod = "GET")
    @GetMapping("/sector/all")
    public R<List<StockBlockDomain>> getStockBlockInfo() {
        return stockService.getStockBlockInfo();
    }

    /**
     * 分页查询最新股票数据
     * 注解RequestParam：
     * value：设定地址中的对应参数
     * required：设定是否必须
     * defaultValue：设定默认值
     *
     * @param page
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "分页查询最新股票数据", notes = "分页查询最新股票数据", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "int", required = false, type = "path"),
            @ApiImplicitParam(name = "pageSize", value = "页码大小", dataType = "int", required = false, type = "path")
    })
    @GetMapping("/stock/all")
    public R<PageResult<StockUpDownDomain>> getStockInfoByPage(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                                                               @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize) {
        return stockService.getStockInfoByPage(page, pageSize);
    }

    /**
     * 查询涨幅最高前4条股票数据
     *
     * @return
     */
    @ApiOperation(value = "查询涨幅最高前4条数据 ", notes = "查询涨幅最高前4条数据", httpMethod = "GET")
    @GetMapping("/stock/increase")
    public R<List<StockUpDownDomain>> getStockInfoByPage() {
        return stockService.getBestStockInfo();
    }

    /**
     * 查询最新交易日内的涨跌停数量
     *
     * @return
     */
    @ApiOperation(value = "查询最新交易日内的涨跌停数量", notes = "查询最新交易日内的涨跌停数量", httpMethod = "GET")
    @GetMapping("/stock/updown/count")
    public R<Map<String, List<Map<String, Object>>>> getStockUpDownCount() {
        return stockService.getStockUpDownCount();
    }

    /**
     * 导出当前页股票数据
     *
     * @param page
     * @param pageSize
     * @param httpServletResponse
     * @return
     */
    @ApiOperation(value = "导出当前页股票数据", notes = "导出当前页股票数据", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "int", required = false, type = "path"),
            @ApiImplicitParam(name = "pageSize", value = "页码大小", dataType = "int", required = false, type = "path")
    })
    @GetMapping("/stock/export")
    public void exportStockInfoByPage(@RequestParam(value = "page", required = false, defaultValue = "1") Integer page,
                                      @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                                      HttpServletResponse httpServletResponse) {
        stockService.exportStockInfoByPage(page, pageSize, httpServletResponse);
    }

    /**
     * 统计A股大盘T日和T-1日成交量
     *
     * @return
     */
    @ApiOperation(value = "统计A股大盘T日和T-1日成交量", notes = "统计A股大盘T日和T-1日成交量", httpMethod = "GET")
    @GetMapping("/stock/tradeAmt")
    public R<Map<String, List>> stockTradeAmoComparsion() {
        return stockService.stockTradeAmoComparsion();
    }

    /**
     * 统计个股（A股）分时涨跌幅度（根据涨跌幅划分区间）
     *
     * @return
     */
    @ApiOperation(value = "统计个股（A股）分时涨跌幅度（根据涨跌幅划分区间）", notes = "统计个股（A股）分时涨跌幅度（根据涨跌幅划分区间）", httpMethod = "GET")
    @GetMapping("/stock/updown")
    public R<Map> stockTimeSharingUpDown() {
        return stockService.stockTimeSharingUpDown();
    }

    /**
     * 查询个股的分时行情数据，也就是统计指定股票T日每分钟的交易数据
     *
     * @param stockCode
     * @return
     */
    @GetMapping("/stock/screen/time-sharing")
    @ApiOperation(value = "查询个股的分时行情数据", notes = "查询个股的分时行情数据", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "股票代码", dataType = "string", required = true, type = "query")
    })
    public R<List<Stock4MinuteDomain>> stockDetailDataEveryMinute(@RequestParam(value = "code", required = true) String stockCode) {
        return stockService.stockDetailDataEveryMinute(stockCode);
    }

    /**
     * 获取个股日K线数据
     *
     * @param stockCode
     * @return
     */
    @GetMapping("/stock/screen/dkline")
    @ApiOperation(value = "获取个股日K线数据", notes = "获取个股日K线数据", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "股票代码", dataType = "string", required = true, type = "query")
    })
    public R<List<Stock4EveryDayDomain>> stockDayKLine(@RequestParam(value = "code", required = true) String stockCode) {
        return stockService.stockDayKLine(stockCode);
    }

    /**
     * 获取外盘指数行情数据，根据时间和大盘点数降序排序取前4条
     * @return
     */
    @ApiOperation(value = "获取外盘指数行情数据", notes = "获取外盘指数行情数据", httpMethod = "GET")
    @GetMapping("/external/index")
    public R<List<OuterMarketDomain>> getOuterMarketInfo(){
        return stockService.getOuterMarketInfo();
    }

    /**
     * 据输入的个股代码，进行模糊查询
     * @param searchStr
     * @return
     */
    @ApiOperation(value = "根据个股代码模糊查询", notes = "根据个股代码模糊查询", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "searchStr", value = "输入框内容", dataType = "string")
    })
    @GetMapping("/stock/search")
    public R<List<Map<String, String>>> searchStockByCode(@RequestParam(value = "searchStr") String searchStr){
        return stockService.searchStockByCode(searchStr);
    }

    /**
     * 查询个股主营业务
     * @param stockCode
     * @return
     */
    @ApiOperation(value = "查询个股主营业务", notes = "查询个股主营业务", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "股票代码", dataType = "string", required = true)
    })
    @GetMapping("/stock/describe")
    public R<StockDescribeDataDomain> getStockMainBusiness(@RequestParam(value = "code", required = true) String stockCode){
        return stockService.getStockMainBusiness(stockCode);
    }

    /**
     * 获取股票周k线数据
     * @param stockCode
     * @return
     */
    @ApiOperation(value = "获取股票周k线数据", notes = "获取股票周k线数据", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "股票代码", dataType = "string", required = true)
    })
    @GetMapping("/stock/screen/weekkline")
    public R<List<Stock4EveryWeekDomain>> getStockEveryWeekInfo(@RequestParam(value = "code", required = true) String stockCode){
        return stockService.getStockEveryWeekInfo(stockCode);
    }

    /**
     * 获取个股最新分时行情数据
     * @param stockCode
     * @return
     */
    @ApiOperation(value = "获取个股最新分时行情数据", notes = "获取个股最新分时行情数据", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "股票编码", dataType = "string", required = true)
    })
    @GetMapping("/stock/screen/second/detail")
    public R<StockRtDomain> getStockRtInfo(@RequestParam(value = "code", required = true) String stockCode){
        return stockService.getStockRtInfo(stockCode);
    }

    /**
     * 获取个股交易流水行情数据，取最新的前十条
     * @param stockCode
     * @return
     */
    @ApiOperation(value = "获取个股交易流水行情数据", notes = "获取个股交易流水行情数据", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "code", value = "股票编码", dataType = "string", required = true)
    })
    @GetMapping("/stock/screen/second")
    public R<List<SrockRtTransactionFlowDomain>> getSrockRtTransactionFlowInfo(@RequestParam(value = "code", required = true) String stockCode){
        return stockService.getSrockRtTransactionFlowInfo(stockCode);
    }
}
